package com.qf.wangqing.sportsnews.fragment.matchsecond;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qf.wangqing.sportsnews.BR;
import com.qf.wangqing.sportsnews.MyApplication;
import com.qf.wangqing.sportsnews.R;
import com.qf.wangqing.sportsnews.adapter.CommentAdapter;
import com.qf.wangqing.sportsnews.bean.cornpetition.cornpeitionbean.CornpetitionLivewordsEntity;
import com.qf.wangqing.sportsnews.bean.cornpetition.cornpeitionbean.CornpetitionRootEntity;
import com.qf.wangqing.sportsnews.databinding.FragmentMatchTelecastBinding;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class MatchTelecastFragment extends Fragment implements Callback<CornpetitionRootEntity> {
    private FragmentMatchTelecastBinding binding;
    private CommentAdapter adapter;
  //  private CommentRecyclerAdapter<CornpetitionLivewordsEntity> adapter;



    public MatchTelecastFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {



         binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.fragment_match_telecast, container, false);
          adapter = new CommentAdapter<>(getActivity(), new ArrayList<CornpetitionLivewordsEntity>(), R.layout.fragment_math_telecast_item,BR.math );
          binding.mathListview.setAdapter(adapter);
//        HashMap<Class<?>, Pair<Integer,Integer>> map = new HashMap<>();
//        map.put(null,Pair.create(R.layout.fragment_math_telecast_item, BR.math));
//        adapter=new CommentRecyclerAdapter(getContext(),new ArrayList<CornpetitionLivewordsEntity>(),map);
       //binding.matnListview.setAdapter(adapter);
         return binding.getRoot() ;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        MyApplication application = (MyApplication) getActivity().getApplication();
        application.getCompetitionService().getWords().enqueue(this);
    }

    @Override
    public void onResponse(Call<CornpetitionRootEntity> call, Response<CornpetitionRootEntity> response) {
        CornpetitionRootEntity body=response.body();
        Log.d("1620", "onResponse: "+response.body());
        adapter.addAll(response.body().getData().getContest_full().getLive_words());

    }

    @Override
    public void onFailure(Call<CornpetitionRootEntity> call, Throwable t) {

    }
}